package apps.softtech.fastmarket.adapter;

import java.util.ArrayList;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import apps.softtech.Utility.ApplicationConstants;
import apps.softtech.fastmarket.R;
import apps.softtech.fastmarket.model.UserInfo;

public class AdapterTheirProfileFollower extends BaseAdapter{
	ArrayList<UserInfo> mUserInfosList = new ArrayList<UserInfo>();
	LayoutInflater inf;
	Context mContext;
	DisplayImageOptions options;
	public AdapterTheirProfileFollower(Context mContext,ArrayList<UserInfo> mUserInfosList, DisplayImageOptions options){
		this.mContext = mContext;
		this.options = options;
		this.mUserInfosList = mUserInfosList;
		inf = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		if(mUserInfosList.size()==0){
			return 1;
		}
		return mUserInfosList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View vi, ViewGroup arg2) {
		if(mUserInfosList.size()==0|| mUserInfosList==null){
			vi = inf.inflate(R.layout.search_no_result, null);
			TextView tvTitle = (TextView)vi.findViewById(R.id.tvNoResult);
			tvTitle.setText(mContext.getResources().getString(R.string.no_follower));
			return vi;
		}
		ViewHolder vh = null;
		if(vi==null){
			vh = new ViewHolder();
			vi = inf.inflate(R.layout.item_my_profile_follower, null);
			vh.tvTheirInfo = (TextView)vi.findViewById(R.id.tvMyProfileFollowerInfo);
			vh.ivTheirFollower = (ImageView)vi.findViewById(R.id.ivMyProfileFollower);
			vh.btFollow = (Button)vi.findViewById(R.id.btMyProfileFollower);
			vh.btFollow.setText(mContext.getResources().getString(R.string.follow));
			vi.setTag(vh);
		}else{
			vh = (ViewHolder) vi.getTag();
		}
			vh.tvTheirInfo.setText(mUserInfosList.get(position).getUserName());
			String url = ApplicationConstants.BASE_URL+ mUserInfosList.get(position).getAvatarPath();
			ImageLoader.getInstance().displayImage(url, vh.ivTheirFollower, options);
			vh.btFollow.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					
				}
			});
		return vi;
	}
	class ViewHolder{
		TextView tvTheirInfo;
		ImageView ivTheirFollower;
		Button btFollow;
	}
}
